package simulation;

public class SimpleBankSystem2043 {
    long[] balance;

    public SimpleBankSystem2043(long[] balance) {
        this.balance = balance;
    }

    public boolean transfer(int account1, int account2, long money) {
        account1=account1-1;
        account2 = account2-1;
        if (account1 >= 0 && account1 < balance.length && account2 >= 0 && account2 < balance.length && balance[account1] - money >= 0) {
            balance[account1] = balance[account1] - money;
            balance[account2] = balance[account2] + money;
            return true;
        } else {
            return false;
        }
    }

    public boolean deposit(int account, long money) {
        account=account-1;
        if (account >= 0 && account < balance.length) {
            balance[account] += money;
            return true;
        } else {
            return false;
        }
    }

    public boolean withdraw(int account, long money) {
        account=account-1;
        if(account>=0&&account< balance.length&&balance[account]-money>=0){
            balance[account]=balance[account]-money;
            return true;
        }else {
            return false;
        }
    }
}
